<?php
define("EW_PAGE_ID", "search", TRUE); // Page ID
define("EW_TABLE_NAME", 'product', TRUE);
?>
<?php 
session_start(); // Initialize session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg50.php" ?>
<?php include "ewmysql50.php" ?>
<?php include "phpfn50.php" ?>
<?php include "productinfo.php" ?>
<?php include "userfn50.php" ?>
<?php include "usersinfo.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Open connection to the database
$conn = ew_Connect();
?>
<?php
$Security = new cAdvancedSecurity();
?>
<?php
if (!$Security->IsLoggedIn()) $Security->AutoLogin();
$Security->LoadCurrentUserLevel('product');
if (!$Security->IsLoggedIn()) {
	$Security->SaveLastUrl();
	Page_Terminate("login.php");
}
if (!$Security->CanSearch()) {
	$Security->SaveLastUrl();
	Page_Terminate("productlist.php");
}
?>
<?php

// Common page loading event (in userfn*.php)
Page_Loading();
?>
<?php

// Page load event, used in current page
Page_Load();
?>
<?php
$product->Export = @$_GET["export"]; // Get export parameter
$sExport = $product->Export; // Get export parameter, used in header
$sExportFile = $product->TableVar; // Get export file, used in header
?>
<?php

// Get action
$product->CurrentAction = @$_POST["a_search"];
switch ($product->CurrentAction) {
	case "S": // Get Search Criteria

		// Build search string for advanced search, remove blank field
		$sSrchStr = BuildAdvancedSearch();
		if ($sSrchStr <> "") {
			Page_Terminate("productlist.php?" . $sSrchStr); // Go to list page
		}
		break;
	default: // Restore search settings
		LoadAdvancedSearch();
}

// Render row for search
$product->RowType = EW_ROWTYPE_SEARCH;
RenderRow();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--
var EW_PAGE_ID = "search"; // Page id
var EW_SHOW_HIGHLIGHT = "Show highlight"; 
var EW_HIDE_HIGHLIGHT = "Hide highlight";

//-->
</script>
<script type="text/javascript">
<!--

function ew_ValidateForm(fobj) {
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
	for (i=0; i<rowcnt; i++) {
		infix = (fobj.key_count) ? String(i+1) : "";
		elm = fobj.elements["x" + infix + "_pro_id"];
		if (elm && !ew_CheckInteger(elm.value)) {
			if (!ew_OnError(elm, "Incorrect integer - Product ID"))
				return false; 
		}
		elm = fobj.elements["x" + infix + "_pro_price"];
		if (elm && !ew_CheckNumber(elm.value)) {
			if (!ew_OnError(elm, "Incorrect floating point number - Price"))
				return false; 
		}
		elm = fobj.elements["x" + infix + "_pro_price_discount"];
		if (elm && !ew_CheckNumber(elm.value)) {
			if (!ew_OnError(elm, "Incorrect floating point number - Price Discount"))
				return false; 
		}
		elm = fobj.elements["x" + infix + "_pro_dateadd"];
		if (elm && !ew_CheckEuroDate(elm.value)) {
			if (!ew_OnError(elm, "Incorrect date, format = dd/mm/yyyy - Date Add"))
				return false; 
		}
	}
	return true;
}

//-->
</script>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
<script type="text/javascript">
<!--
_width_multiplier = 16;
_height_multiplier = 60;
var ew_DHTMLEditors = [];

function ew_UpdateTextArea() {
	if (typeof ew_DHTMLEditors != 'undefined' &&
		typeof FCKeditorAPI != 'undefined') {			
			var inst;			
			for (inst in FCKeditorAPI.__Instances)
				FCKeditorAPI.__Instances[inst].UpdateLinkedField();
	}
}

//-->
</script>
<link rel="stylesheet" type="text/css" media="all" href="calendar/calendar-win2k-1.css" title="win2k-1" />
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<p><span class="phpmaker">Search TABLE: product<br><br><a href="productlist.php">Back to List</a></span></p>
<form name="fproductsearch" id="fproductsearch" action="productsrch.php" method="post">
<p>
<input type="hidden" name="a_search" id="a_search" value="S">
<table class="ewTable">
	<tr class="ewTableRow">
		<td class="ewTableHeader">Product ID</td>
		<td<?php echo $product->pro_id->CellAttributes() ?>><span class="ewSearchOpr">=<input type="hidden" name="z_pro_id" id="z_pro_id" value="="></span></td>
		<td<?php echo $product->pro_id->CellAttributes() ?>><span class="phpmaker">
<input type="text" name="x_pro_id" id="x_pro_id"  value="<?php echo $product->pro_id->EditValue ?>"<?php echo $product->pro_id->EditAttributes() ?>>
</span></td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">Parent ID</td>
		<td<?php echo $product->parent_id->CellAttributes() ?>><span class="ewSearchOpr">=<input type="hidden" name="z_parent_id" id="z_parent_id" value="="></span></td>
		<td<?php echo $product->parent_id->CellAttributes() ?>><span class="phpmaker">
<select id="x_parent_id" name="x_parent_id" onChange="ew_AjaxUpdateOpt(this.form.x_sub_id, this, true);"<?php echo $product->parent_id->EditAttributes() ?>>
<!--option value="">Please Select</option-->
<?php
if (is_array($product->parent_id->EditValue)) {
	$arwrk = $product->parent_id->EditValue;
	$rowswrk = count($arwrk);
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($product->parent_id->AdvancedSearch->SearchValue) == strval($arwrk[$rowcntwrk][0])) ? " selected" : "";	
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
			}
}
?>
</select>
</span></td>
	</tr>
	<tr class="ewTableRow">
		<td class="ewTableHeader">Sub ID</td>
		<td<?php echo $product->sub_id->CellAttributes() ?>><span class="ewSearchOpr">=<input type="hidden" name="z_sub_id" id="z_sub_id" value="="></span></td>
		<td<?php echo $product->sub_id->CellAttributes() ?>><span class="phpmaker">
<select id="x_sub_id" name="x_sub_id"<?php echo $product->sub_id->EditAttributes() ?>>
<!--option value="">Please Select</option-->
<?php
if (is_array($product->sub_id->EditValue)) {
	$arwrk = $product->sub_id->EditValue;
	$rowswrk = count($arwrk);
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($product->sub_id->AdvancedSearch->SearchValue) == strval($arwrk[$rowcntwrk][0])) ? " selected" : "";	
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
			}
}
?>
</select>
<?php
$sSqlWrk = "SELECT `sub_id`, `sub_name` FROM `subcat`";
$sSqlWrk .= " WHERE (`parent_id` IN (@FILTER_VALUE))";
$sSqlWrk .= " AND (" . "`sub_type`='3' or `sub_type`='5'" . ")";
$sSqlWrk .= " ORDER BY `sub_order` Desc";
$sSqlWrk = TEAencrypt($sSqlWrk, EW_RANDOM_KEY);
?>
<input type="hidden" name="s_x_sub_id" id="s_x_sub_id" value="<?php echo $sSqlWrk ?>"><input type="hidden" name="lc_x_sub_id" id="lc_x_sub_id" value="2"><input type="hidden" name="ld1_x_sub_id" id="ld1_x_sub_id" value="1"><input type="hidden" name="ld2_x_sub_id" id="ld2_x_sub_id" value="-1"><input type="hidden" name="lft_x_sub_id" id="lft_x_sub_id" value="1">
</span></td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">Title</td>
		<td<?php echo $product->pro_title->CellAttributes() ?>><span class="ewSearchOpr">contains<input type="hidden" name="z_pro_title" id="z_pro_title" value="LIKE"></span></td>
		<td<?php echo $product->pro_title->CellAttributes() ?>><span class="phpmaker">
<input type="text" name="x_pro_title" id="x_pro_title"  size="30" maxlength="250" value="<?php echo $product->pro_title->EditValue ?>"<?php echo $product->pro_title->EditAttributes() ?>>
</span></td>
	</tr>
	<tr class="ewTableRow">
		<td class="ewTableHeader">Price</td>
		<td<?php echo $product->pro_price->CellAttributes() ?>><span class="ewSearchOpr">=<input type="hidden" name="z_pro_price" id="z_pro_price" value="="></span></td>
		<td<?php echo $product->pro_price->CellAttributes() ?>><span class="phpmaker">
<input type="text" name="x_pro_price" id="x_pro_price"  size="30" value="<?php echo $product->pro_price->EditValue ?>"<?php echo $product->pro_price->EditAttributes() ?>>
</span></td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">pro warranty</td>
		<td<?php echo $product->pro_warranty->CellAttributes() ?>><span class="ewSearchOpr">contains<input type="hidden" name="z_pro_warranty" id="z_pro_warranty" value="LIKE"></span></td>
		<td<?php echo $product->pro_warranty->CellAttributes() ?>><span class="phpmaker">
<input type="text" name="x_pro_warranty" id="x_pro_warranty"  size="30" maxlength="50" value="<?php echo $product->pro_warranty->EditValue ?>"<?php echo $product->pro_warranty->EditAttributes() ?>>
</span></td>
	</tr>
	<tr class="ewTableRow">
		<td class="ewTableHeader">Quaranty</td>
		<td<?php echo $product->pro_quaranty->CellAttributes() ?>><span class="ewSearchOpr">contains<input type="hidden" name="z_pro_quaranty" id="z_pro_quaranty" value="LIKE"></span></td>
		<td<?php echo $product->pro_quaranty->CellAttributes() ?>><span class="phpmaker">
<input type="text" name="x_pro_quaranty" id="x_pro_quaranty"  size="30" maxlength="40" value="<?php echo $product->pro_quaranty->EditValue ?>"<?php echo $product->pro_quaranty->EditAttributes() ?>>
</span></td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">Price Discount</td>
		<td<?php echo $product->pro_price_discount->CellAttributes() ?>><span class="ewSearchOpr">=<input type="hidden" name="z_pro_price_discount" id="z_pro_price_discount" value="="></span></td>
		<td<?php echo $product->pro_price_discount->CellAttributes() ?>><span class="phpmaker">
<input type="text" name="x_pro_price_discount" id="x_pro_price_discount"  size="30" value="<?php echo $product->pro_price_discount->EditValue ?>"<?php echo $product->pro_price_discount->EditAttributes() ?>>
</span></td>
	</tr>
	<tr class="ewTableRow">
		<td class="ewTableHeader">Content</td>
		<td<?php echo $product->pro_content->CellAttributes() ?>><span class="ewSearchOpr">contains<input type="hidden" name="z_pro_content" id="z_pro_content" value="LIKE"></span></td>
		<td<?php echo $product->pro_content->CellAttributes() ?>><span class="phpmaker">
<textarea name="x_pro_content" id="x_pro_content" cols="35" rows="20"<?php echo $product->pro_content->EditAttributes() ?>><?php echo $product->pro_content->EditValue ?></textarea>
</span></td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">Detail</td>
		<td<?php echo $product->pro_detail->CellAttributes() ?>><span class="ewSearchOpr">contains<input type="hidden" name="z_pro_detail" id="z_pro_detail" value="LIKE"></span></td>
		<td<?php echo $product->pro_detail->CellAttributes() ?>><span class="phpmaker">
<textarea name="x_pro_detail" id="x_pro_detail" cols="35" rows="20"<?php echo $product->pro_detail->EditAttributes() ?>><?php echo $product->pro_detail->EditValue ?></textarea>
</span></td>
	</tr>
	<tr class="ewTableRow">
		<td class="ewTableHeader">Date Add</td>
		<td<?php echo $product->pro_dateadd->CellAttributes() ?>><span class="ewSearchOpr">=<input type="hidden" name="z_pro_dateadd" id="z_pro_dateadd" value="="></span></td>
		<td<?php echo $product->pro_dateadd->CellAttributes() ?>><span class="phpmaker">
<input type="text" name="x_pro_dateadd" id="x_pro_dateadd"  value="<?php echo $product->pro_dateadd->EditValue ?>"<?php echo $product->pro_dateadd->EditAttributes() ?>>
&nbsp;<img src="images/ew_calendar.gif" id="cx_pro_dateadd" alt="Pick a Date" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup(
{
inputField : "x_pro_dateadd", // ID of the input field
ifFormat : "%d/%m/%Y", // the date format
button : "cx_pro_dateadd" // ID of the button
}
);
</script>
</span></td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">Home Page</td>
		<td<?php echo $product->pro_homepage->CellAttributes() ?>><span class="ewSearchOpr">=<input type="hidden" name="z_pro_homepage" id="z_pro_homepage" value="="></span></td>
		<td<?php echo $product->pro_homepage->CellAttributes() ?>><span class="phpmaker">
<?php
$arwrk = $product->pro_homepage->EditValue;
if (is_array($arwrk)) {
	$armultiwrk= explode(",", strval($product->pro_homepage->AdvancedSearch->SearchValue));
	$rowswrk = count($arwrk);
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = "";
		for ($ari = 0; $ari < count($armultiwrk); $ari++) {
			if (strval($arwrk[$rowcntwrk][0]) == trim(strval($armultiwrk[$ari]))) {
				$selwrk = " checked";
				break;
			}
		}
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<input type="checkbox" name="x_pro_homepage[]" id="x_pro_homepage[]" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $product->pro_homepage->EditAttributes() ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
	}
}
?>
</span></td>
	</tr>
	<tr class="ewTableRow">
		<td class="ewTableHeader">Type</td>
		<td<?php echo $product->pro_type->CellAttributes() ?>><span class="ewSearchOpr">=<input type="hidden" name="z_pro_type" id="z_pro_type" value="="></span></td>
		<td<?php echo $product->pro_type->CellAttributes() ?>><span class="phpmaker">
<?php
$arwrk = $product->pro_type->EditValue;
if (is_array($arwrk)) {
	$rowswrk = count($arwrk);
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($product->pro_type->AdvancedSearch->SearchValue) == strval($arwrk[$rowcntwrk][0])) ? " checked" : "";
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<input type="radio" name="x_pro_type" id="x_pro_type" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $product->pro_type->EditAttributes() ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
	}
}
?>
</span></td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">Active</td>
		<td<?php echo $product->pro_active->CellAttributes() ?>><span class="ewSearchOpr">=<input type="hidden" name="z_pro_active" id="z_pro_active" value="="></span></td>
		<td<?php echo $product->pro_active->CellAttributes() ?>><span class="phpmaker">
<?php
$arwrk = $product->pro_active->EditValue;
if (is_array($arwrk)) {
	$armultiwrk= explode(",", strval($product->pro_active->AdvancedSearch->SearchValue));
	$rowswrk = count($arwrk);
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = "";
		for ($ari = 0; $ari < count($armultiwrk); $ari++) {
			if (strval($arwrk[$rowcntwrk][0]) == trim(strval($armultiwrk[$ari]))) {
				$selwrk = " checked";
				break;
			}
		}
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<input type="checkbox" name="x_pro_active[]" id="x_pro_active[]" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $product->pro_active->EditAttributes() ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
	}
}
?>
</span></td>
	</tr>
</table>
<p>
<input type="button" name="Action" id="Action" value="  Search  " onClick="ew_SubmitForm(this.form);">
<input type="button" name="Reset" id="Reset" value="   Reset   " onclick="ew_ClearForm(this.form);">
</form>
<script type="text/javascript">
<!--
ew_CreateEditor(); // Create DHTML editor(s)

//-->
</script>
<script language="JavaScript">
<!--
var f = document.fproductsearch;
ew_AjaxUpdateOpt(f.x_sub_id, f.x_parent_id, false);

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php include "footer.php" ?>
<?php

// If control is passed here, simply terminate the page without redirect
Page_Terminate();

// -----------------------------------------------------------------
//  Subroutine Page_Terminate
//  - called when exit page
//  - clean up connection and objects
//  - if url specified, redirect to url, otherwise end response
function Page_Terminate($url = "") {
	global $conn;

	// Page unload event, used in current page
	Page_Unload();

	// Global page unloaded event (in userfn*.php)
	Page_Unloaded();

	 // Close Connection
	$conn->Close();

	// Go to url if specified
	if ($url <> "") {
		ob_end_clean();
		header("Location: $url");
	}
	exit();
}
?>
<?php

// Build advanced search
function BuildAdvancedSearch() {
	global $product;
	$sSrchUrl = "";

	// Field pro_id
	BuildSearchUrl($sSrchUrl, $product->pro_id, @$_POST["x_pro_id"], @$_POST["z_pro_id"], @$_POST["v_pro_id"], @$_POST["y_pro_id"], @$_POST["w_pro_id"]);

	// Field parent_id
	BuildSearchUrl($sSrchUrl, $product->parent_id, @$_POST["x_parent_id"], @$_POST["z_parent_id"], @$_POST["v_parent_id"], @$_POST["y_parent_id"], @$_POST["w_parent_id"]);

	// Field sub_id
	BuildSearchUrl($sSrchUrl, $product->sub_id, @$_POST["x_sub_id"], @$_POST["z_sub_id"], @$_POST["v_sub_id"], @$_POST["y_sub_id"], @$_POST["w_sub_id"]);

	// Field pro_title
	BuildSearchUrl($sSrchUrl, $product->pro_title, @$_POST["x_pro_title"], @$_POST["z_pro_title"], @$_POST["v_pro_title"], @$_POST["y_pro_title"], @$_POST["w_pro_title"]);

	// Field pro_price
	BuildSearchUrl($sSrchUrl, $product->pro_price, @$_POST["x_pro_price"], @$_POST["z_pro_price"], @$_POST["v_pro_price"], @$_POST["y_pro_price"], @$_POST["w_pro_price"]);

	// Field pro_warranty
	BuildSearchUrl($sSrchUrl, $product->pro_warranty, @$_POST["x_pro_warranty"], @$_POST["z_pro_warranty"], @$_POST["v_pro_warranty"], @$_POST["y_pro_warranty"], @$_POST["w_pro_warranty"]);

	// Field pro_quaranty
	BuildSearchUrl($sSrchUrl, $product->pro_quaranty, @$_POST["x_pro_quaranty"], @$_POST["z_pro_quaranty"], @$_POST["v_pro_quaranty"], @$_POST["y_pro_quaranty"], @$_POST["w_pro_quaranty"]);

	// Field pro_price_discount
	BuildSearchUrl($sSrchUrl, $product->pro_price_discount, @$_POST["x_pro_price_discount"], @$_POST["z_pro_price_discount"], @$_POST["v_pro_price_discount"], @$_POST["y_pro_price_discount"], @$_POST["w_pro_price_discount"]);

	// Field pro_content
	BuildSearchUrl($sSrchUrl, $product->pro_content, @$_POST["x_pro_content"], @$_POST["z_pro_content"], @$_POST["v_pro_content"], @$_POST["y_pro_content"], @$_POST["w_pro_content"]);

	// Field pro_detail
	BuildSearchUrl($sSrchUrl, $product->pro_detail, @$_POST["x_pro_detail"], @$_POST["z_pro_detail"], @$_POST["v_pro_detail"], @$_POST["y_pro_detail"], @$_POST["w_pro_detail"]);

	// Field pro_dateadd
	BuildSearchUrl($sSrchUrl, $product->pro_dateadd, ew_UnFormatDateTime(@$_POST["x_pro_dateadd"],7), @$_POST["z_pro_dateadd"], @$_POST["v_pro_dateadd"], ew_UnFormatDateTime(@$_POST["y_pro_dateadd"],7), @$_POST["w_pro_dateadd"]);

	// Field pro_homepage
	BuildSearchUrl($sSrchUrl, $product->pro_homepage, @$_POST["x_pro_homepage"], @$_POST["z_pro_homepage"], @$_POST["v_pro_homepage"], @$_POST["y_pro_homepage"], @$_POST["w_pro_homepage"]);

	// Field pro_type
	BuildSearchUrl($sSrchUrl, $product->pro_type, @$_POST["x_pro_type"], @$_POST["z_pro_type"], @$_POST["v_pro_type"], @$_POST["y_pro_type"], @$_POST["w_pro_type"]);

	// Field pro_active
	BuildSearchUrl($sSrchUrl, $product->pro_active, @$_POST["x_pro_active"], @$_POST["z_pro_active"], @$_POST["v_pro_active"], @$_POST["y_pro_active"], @$_POST["w_pro_active"]);
	return $sSrchUrl;
}

// Function to build search URL
function BuildSearchUrl(&$Url, &$Fld, $FldVal, $FldOpr, $FldCond, $FldVal2, $FldOpr2) {
	$sWrk = "";
	$FldParm = substr($Fld->FldVar, 2);
	$FldVal = ew_StripSlashes($FldVal);
	if (is_array($FldVal)) $FldVal = implode(",", $FldVal);
	$FldVal2 = ew_StripSlashes($FldVal2);
	if (is_array($FldVal2)) $FldVal2 = implode(",", $FldVal2);
	$FldOpr = strtoupper(trim($FldOpr));
	if ($FldOpr == "BETWEEN") {
		$IsValidValue = ($Fld->FldDataType <> EW_DATATYPE_NUMBER) ||
			($Fld->FldDataType == EW_DATATYPE_NUMBER && is_numeric($FldVal) && is_numeric($FldVal2));
		if ($FldVal <> "" && $FldVal2 <> "" && $IsValidValue) {
			$sWrk = "x_" . $FldParm . "=" . urlencode($FldVal) .
				"&y_" . $FldParm . "=" . urlencode($FldVal2) .
				"&z_" . $FldParm . "=" . urlencode($FldOpr);
		}
	} elseif ($FldOpr == "IS NULL" || $FldOpr == "IS NOT NULL") {
		$sWrk = "x_" . $FldParm . "=" . urlencode($FldVal) .
			"&z_" . $FldParm . "=" . urlencode($FldOpr);
	} else {
		$IsValidValue = ($Fld->FldDataType <> EW_DATATYPE_NUMBER) ||
			($Fld->FldDataType = EW_DATATYPE_NUMBER && is_numeric($FldVal));
		if ($FldVal <> "" && $IsValidValue && ew_IsValidOpr($FldOpr, $Fld->FldDataType)) {
			$sWrk = "x_" . $FldParm . "=" . urlencode($FldVal) .
				"&z_" . $FldParm . "=" . urlencode($FldOpr);
		}
		$IsValidValue = ($Fld->FldDataType <> EW_DATATYPE_NUMBER) ||
			($Fld->FldDataType = EW_DATATYPE_NUMBER && is_numeric($FldVal2));
		if ($FldVal2 <> "" && $IsValidValue && ew_IsValidOpr($FldOpr2, $Fld->FldDataType)) {
			if ($sWrk <> "") $sWrk .= "&v_" . $FldParm . "=" . urlencode($FldCond) . "&";
			$sWrk .= "&y_" . $FldParm . "=" . urlencode($FldVal2) .
				"&w_" . $FldParm . "=" . urlencode($FldOpr2);
		}
	}
	if ($sWrk <> "") {
		if ($Url <> "") $Url .= "&";
		$Url .= $sWrk;
	}
}
?>
<?php

// Render row values based on field settings
function RenderRow() {
	global $conn, $Security, $product;

	// Call Row Rendering event
	$product->Row_Rendering();

	// Common render codes for all row types
	if ($product->RowType == EW_ROWTYPE_VIEW) { // View row
	} elseif ($product->RowType == EW_ROWTYPE_ADD) { // Add row
	} elseif ($product->RowType == EW_ROWTYPE_EDIT) { // Edit row
	} elseif ($product->RowType == EW_ROWTYPE_SEARCH) { // Search row

		// pro_id
		$product->pro_id->EditCustomAttributes = "";
		$product->pro_id->EditValue = ew_HtmlEncode($product->pro_id->AdvancedSearch->SearchValue);

		// parent_id
		$product->parent_id->EditCustomAttributes = "";
		$sSqlWrk = "SELECT `parent_id`, `parent_name` FROM `parent`";
		$sSqlWrk .= " ORDER BY `parent_order` Desc";
		$rswrk = $conn->Execute($sSqlWrk);
		$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
		if ($rswrk) $rswrk->Close();
		array_unshift($arwrk, array("", "Please Select"));
		$product->parent_id->EditValue = $arwrk;

		// sub_id
		$product->sub_id->EditCustomAttributes = "";
		$sSqlWrk = "SELECT `sub_id`, `sub_name`, `parent_id` FROM `subcat`";
		if (trim(strval($product->sub_id->AdvancedSearch->SearchValue)) == "") {
			$sSqlWrk .= " WHERE 0=1";
		} else {
			$sSqlWrk .= " WHERE `sub_id` = " . ew_AdjustSql($product->sub_id->AdvancedSearch->SearchValue) . "";
		}
		$sSqlWrk .= " AND (" . "`sub_type`='3' or `sub_type`='5'" . ")";
		$rswrk = $conn->Execute($sSqlWrk);
		$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
		if ($rswrk) $rswrk->Close();
		array_unshift($arwrk, array("", "Please Select", ""));
		$product->sub_id->EditValue = $arwrk;

		// pro_title
		$product->pro_title->EditCustomAttributes = "";
		$product->pro_title->EditValue = ew_HtmlEncode($product->pro_title->AdvancedSearch->SearchValue);

		// pro_price
		$product->pro_price->EditCustomAttributes = "";
		$product->pro_price->EditValue = ew_HtmlEncode($product->pro_price->AdvancedSearch->SearchValue);

		// pro_warranty
		$product->pro_warranty->EditCustomAttributes = "";
		$product->pro_warranty->EditValue = ew_HtmlEncode($product->pro_warranty->AdvancedSearch->SearchValue);

		// pro_quaranty
		$product->pro_quaranty->EditCustomAttributes = "";
		$product->pro_quaranty->EditValue = ew_HtmlEncode($product->pro_quaranty->AdvancedSearch->SearchValue);

		// pro_price_discount
		$product->pro_price_discount->EditCustomAttributes = "";
		$product->pro_price_discount->EditValue = ew_HtmlEncode($product->pro_price_discount->AdvancedSearch->SearchValue);

		// pro_smallimg
		$product->pro_smallimg->EditCustomAttributes = "";
		$product->pro_smallimg->EditValue = $product->pro_smallimg->AdvancedSearch->SearchValue;

		// pro_bigimg
		$product->pro_bigimg->EditCustomAttributes = "";
		$product->pro_bigimg->EditValue = $product->pro_bigimg->AdvancedSearch->SearchValue;

		// pro_content
		$product->pro_content->EditCustomAttributes = "";
		$product->pro_content->EditValue = ew_HtmlEncode($product->pro_content->AdvancedSearch->SearchValue);

		// pro_detail
		$product->pro_detail->EditCustomAttributes = "";
		$product->pro_detail->EditValue = ew_HtmlEncode($product->pro_detail->AdvancedSearch->SearchValue);

		// pro_dateadd
		$product->pro_dateadd->EditCustomAttributes = "";
		$product->pro_dateadd->EditValue = ew_HtmlEncode(ew_FormatDateTime($product->pro_dateadd->AdvancedSearch->SearchValue, 7));

		// pro_homepage
		$product->pro_homepage->EditCustomAttributes = "";
		$arwrk = array();
		$arwrk[] = array("1", "Home Page");
		$product->pro_homepage->EditValue = $arwrk;

		// pro_type
		$product->pro_type->EditCustomAttributes = "";
		$arwrk = array();
		$arwrk[] = array("1", "San pham khuyen mai");
		$arwrk[] = array("2", "San pham moi");
		$arwrk[] = array("3", "San pham ua chuong");
		$arwrk[] = array("4", "San pham do choi");
		$arwrk[] = array("5", "San pham ban chay");
		$product->pro_type->EditValue = $arwrk;

		// pro_active
		$product->pro_active->EditCustomAttributes = "";
		$arwrk = array();
		$arwrk[] = array("1", "Active");
		$product->pro_active->EditValue = $arwrk;
	}

	// Call Row Rendered event
	$product->Row_Rendered();
}
?>
<?php

// Load advanced search
function LoadAdvancedSearch() {
	global $product;
	$product->pro_id->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_pro_id");
	$product->parent_id->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_parent_id");
	$product->sub_id->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_sub_id");
	$product->pro_title->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_pro_title");
	$product->pro_price->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_pro_price");
	$product->pro_warranty->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_pro_warranty");
	$product->pro_quaranty->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_pro_quaranty");
	$product->pro_price_discount->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_pro_price_discount");
	$product->pro_content->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_pro_content");
	$product->pro_detail->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_pro_detail");
	$product->pro_dateadd->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_pro_dateadd");
	$product->pro_homepage->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_pro_homepage");
	$product->pro_type->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_pro_type");
	$product->pro_active->AdvancedSearch->SearchValue = $product->getAdvancedSearch("x_pro_active");
}
?>
<?php

// Page Load event
function Page_Load() {

	//echo "Page Load";
}

// Page Unload event
function Page_Unload() {

	//echo "Page Unload";
}
?>
